package com.rain.controller;

import com.rain.enums.ResponseCodeEnum;

import com.rain.query.ResponseVO;

/**
 * 基础控制器基类
 * <p>
 * 提供统一的响应封装方法，避免重复代码
 *
 * @author Rain
 */
public abstract class BaseController {

    // ================== 静态常量 ==================

    /**
     * 成功状态标识
     */
    protected static final String STATUS_SUCCESS = "success";

    /**
     * 错误状态标识
     */
    protected static final String STATUS_ERROR = "error";

    // ================== 公共响应方法 ==================

    /**
     * 返回成功响应（带数据）
     *
     * @param data 数据
     * @param <T>  泛型类型
     * @return ResponseVO<T>
     */
    protected <T> ResponseVO<T> getSuccessResponseVO(T data) {
        ResponseVO<T> responseVO = new ResponseVO<>();
        responseVO.setStatus(STATUS_SUCCESS);
        responseVO.setCode(ResponseCodeEnum.CODE_200.getCode());
        responseVO.setMsg(ResponseCodeEnum.CODE_200.getMsg());
        responseVO.setData(data);
        return responseVO;
    }

    protected <T> ResponseVO<T> getErrorResponseVO(ResponseCodeEnum responseCodeEnum) {
        ResponseVO<T> responseVO = new ResponseVO<>();
        responseVO.setStatus(STATUS_ERROR);
        responseVO.setCode(responseCodeEnum.getCode());
        responseVO.setMsg(responseCodeEnum.getMsg());
        responseVO.setData(null);
        return responseVO;
    }
}
